#ifndef ASTAR_H
#define ASTAR_H

#include <list>
#include <vector>
#include <algorithm>
#include <cmath>

#include "Application.h"

#define RIGHT { 0, 1}
#define LEFT  { 0,-1}
#define UP    {-1, 0}
#define DOWN  { 1, 0}

class AStar
{
public:
	struct Node
	{
		unsigned int X;
		unsigned int Y;
		unsigned int Cost;
		unsigned int Heuristic;
		unsigned int F;
		Node* Parent;
	};

	AStar(Application& _app);
	virtual ~AStar();

	void SetMap(char** _map) { m_map = _map; };
	void SetGoal(std::pair<unsigned int, unsigned int> _goal) { m_end = _goal; };
	void FindPath(std::pair<unsigned int, unsigned int> _start);

	const std::list<std::pair<unsigned int, unsigned int>> GetPath() const;

private:
	static unsigned int GetHeuristic(unsigned int _x, unsigned int _y, std::pair<unsigned int, unsigned int> _end);

	bool IsClose(unsigned int _x, unsigned int _y);
	bool IsOpen(unsigned int _x, unsigned int _y);
	Node GetBestNode();

	char** m_map;
	std::pair<unsigned int, unsigned int> m_end;
	std::list<std::pair<unsigned int, unsigned int>> m_path;

	std::list<Node> m_open;
	std::list<Node> m_close;
};

#endif